<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>

<body>
    <button>发送get请求</button>
    <button>发送post请求</button>
    <script>
        // 发送get
        $('button').eq(0).click(function() {
            $.ajax({
                type: 'get',
                url: 'http://localhost:3000/api/getmsg',
                success: function(data) {
                    console.log(data);
                },
                error: function(err) {
                    console.log(err);
                }
            });
        });
        // 发送post
        $('button').eq(1).click(function() {
            $.ajax({
                type: 'post',
                url: 'http://localhost:3000/api/postmsg',
                data: {
                    username: 'momoko'
                },
                success: function(data) {
                    console.log(data);
                },
                error: function(err) {
                    console.log(err);
                }
            });
        });
    </script>
</body>

</html>